<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('仓库-设备列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <label>设备类型：</label>
                            <select name="devType" th:with="type=${@dict.getType('sys_device_type')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                        th:value="${dict.dictValue}"></option>
                            </select>
                        </li>
                        <li class="select-time">
                            <label style="width: 105px;">设备入库时间：</label>
                            <input type="text" class="time-input" id="startTime" placeholder="开始时间"
                                   name="startTime"/>
                            <span>-</span>
                            <input type="text" class="time-input" id="endTime" placeholder="结束时间"
                                   name="endTime"/>
                        </li>
                        <li>
                            <label>机柜SN：</label>
                            <input type="text" name="sn"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <!--<a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="system:device:add">-->
            <!--<i class="fa fa-plus"></i> 添加-->
            <!--</a>-->
            <a class="btn btn-info" onclick="$.table.importExcel()" shiro:hasPermission="system:device:readExcel">
                <i class="fa fa-upload"></i> 设备导入
            </a>
            <!--            <a class="btn btn-primary single disabled" onclick="$.operate.edit()"-->
            <!--               shiro:hasPermission="system:device:edit">-->
            <!--                <i class="fa fa-edit"></i> 划分设备-->
            <!--            </a>-->
            <!--<a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()"-->
            <!--shiro:hasPermission="system:device:remove">-->
            <!--<i class="fa fa-remove"></i> 删除-->
            <!--</a>-->
            <!--<a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="system:device:export">-->
            <!--<i class="fa fa-download"></i> 导出-->
            <!--</a>-->
            <a class="btn btn-primary" onclick="selectFirstColumns()" shiro:hasPermission="system:device:allot">
                <i class="fa fa-edit"></i> 划分设备
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('system:device:edit')}]];
    var removeFlag = [[${@permission.hasPermi('system:device:remove')}]];


    var allotFlag = [[${@permission.hasPermi('system:device:allot')}]];

    var devTypeDatas = [[${@dict.getType('sys_device_type')}]];
    var devStatusDatas = [[${@dict.getType('sys_device_status')}]];

    var deviceStatusDatas = [[${@dict.getType('sys_device_the_life_cycle')}]];

    var prefix = ctx + "system/device";

    $(function () {
        var options = {
            url: prefix + "/warehouseList",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            importUrl: prefix + "/importData",
            modalName: "设备",
            columns: [{
                checkbox: true
            },
                {
                    field: 'id',
                    title: '',
                    visible: false
                },
                {
                    field: 'sn',
                    title: '机柜SN'
                },
                {
                    field: 'devType',
                    title: '设备类型',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(devTypeDatas, value);
                    }
                },
                {
                    field: 'deviceStatus',
                    title: '设备状态',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(deviceStatusDatas, value);
                    }
                },
                {
                    field: 'createTime',
                    title: '入库时间'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];

                        actions.push('<a class="btn btn-success btn-xs ' + allotFlag + '" href="javascript:void(0)" onclick="allotDevOne(\'' + row.id + '\',\'' + row.sn + '\')"><i class="fa fa-edit"></i>划分设备</a> ');
                        // actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');

                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });

    // 分配单台设备
    function allotDevOne(id, sn) {
        var url = prefix + "/allotDevOne/" + id;
        $.modal.open("划分设备", url, 800, 600);
    }

    // 多台设备进行分配
    function selectFirstColumns() {
        var column = $.table.selectFirstColumns();
        if (column == null || column == "") {
            layer.msg("您未选择设备");
            return;
        }
        var url = prefix + "/allotDevAll/" + column;
        $.modal.open("划分设备", url, 800, 600);
    }
</script>
<!-- 导入区域 -->
<script id="importTpl" type="text/template">
    <form enctype="multipart/form-data" class="mt20 mb10">
        <div class="col-xs-offset-1">
            <input type="file" id="file" name="file"/>
            <font color="red" class="pull-left mt10">
                提示：仅允许导入“xls”或“xlsx”格式文件！
            </font>
        </div>
    </form>
</script>
</body>
</html>